<template>
	<view class="mainpadding">
		<view class="xiaohei fonweight titletext" v-if="type==1">我的佣金：
			<text class="xiaohong fonweight sanshier" style="font-size: 40rpx;">{{userInfo.money}}</text>
		</view>
		<view class="xiaohei fonweight titletext" v-if="type==2">我的团队奖励：
			<text class="xiaohong fonweight sanshier" style="font-size: 40rpx;">{{userInfo.team_money}}</text>
		</view>
		<view class="flexleft margin_top">
			<view class="xiaohei fonweight  titletext" style="min-width: 160rpx;">转换积分：</view>
			<input class="input" style="width: 100%;" type="number" placeholder="请输入需要转换的金额" v-model="money">
		</view>
		<view class="sanshier fonweight xiaohong margin_top">注：{{systeminfo.yjzybz}}</view>
		<view class="gudingdb ffffff mainpadding">
			<view class="bigbtn" @click="submit">提交</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				money:"",
				systeminfo:{},
				type:1,//1佣金，2团队奖励
				userInfo:{}
			}
		},
		onLoad(options) {
			this.type = options.type
		},
		onShow() {
			this.userinfo()
			this.system()
		},
		methods: {
			system(){
				httpRequest.request('/api/index/getConfigInfo','GET',{}).then(res => {
					this.systeminfo = res.data
				})
			},
			submit() {
				if(this.money==""){
					httpRequest.toast("请输入需要转换的金额")
					return false
				}
				if(this.type==1){
					if (Number(this.userInfo.money) < Number(this.money)) {
						httpRequest.toast("需要转换的金额不能大于当前剩余佣金")
						return false
					}
				}
				if(this.type==2){
					if (Number(this.userInfo.team_money) < Number(this.money)) {
						httpRequest.toast("需要转换的金额不能大于当前剩余佣金")
						return false
					}
				}
				let url = "/api/user/moneyToScore"
				if(this.type==2){
					url = "/api/user/teamMoneyToScore"
				}
				httpRequest.request(url, 'GET', {
					money:this.money
				}).then(res => {
					httpRequest.toast(res.msg)
					if(res.code==1){
						setTimeout(()=>{
							uni.navigateBack(1)
						},1000)
					}
				})
			},
			userinfo() {
				httpRequest.request('/api/user/index', 'GET', {}).then(res => {
					this.userInfo = res.data
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.input {
		border-radius: 20rpx;
		padding: 20rpx 30rpx;
		background-color: #fff;
	}
</style>
